﻿//var fso = new ActiveXObject(Scripting.FileSystemObject);
//var file = fso.createtextfile;
var editWindow = $('#edit_window');


/**
 * 代码高亮
 */

function highLight(){
	
}



/**
 * 查错
 */

function syntaxError(){
	
}



/**
 * 自动补全代码
 */
var listenInput = false;

function autoComplete (keyCode){
	//"<"被按下
	if (keyCode == 60){
		if (listenInput == false){
			listenInput = true;
			
			
			
		}
		else {
			listenInput = false;
		}
	}
	
	//">"被按下
	else if (keyCode == 62 && listenInput == true){
		var inputCont = editWindow.val().substring(0, getCursorPos('edit_window'));
		listenInput = false;
		
		
		inputCont = inputCont.substring(inputCont.lastIndexOf('<') + 1, getCursorPos('edit_window'))
		
		
		console.log(inputCont)
		
		inputCont = '';
	}
}


/**
 * 获取光标在短连接输入框中的位置
 * @param inputId 框Id
 * @return {*}
 */
function getCursorPos(inputId){
	var inpObj = document.getElementById(inputId);
	if(navigator.userAgent.indexOf("MSIE") > -1) { // IE
		var range = document.selection.createRange();
		range.text = '';
		range.setEndPoint('StartToStart',inpObj.createTextRange());
		return range.text.length;
	} else {
		return inpObj.selectionStart;
	}
}



/**
 * 注册事件
 */

editWindow.on('keypress', function(event){
	event = event || window.event;
	autoComplete(event.keyCode);
})
